package cn.mldn.homework.mvcOutputHelloWord.util;

import java.util.Properties;

import cn.mldn.homework.mvcOutputHelloWord.BIZ.BIZ;
import cn.mldn.homework.mvcOutputHelloWord.DAO.DAO;
import cn.mldn.homework.mvcOutputHelloWord.VIEW.View;

public class ViewFactory
{
	private ConfigReader cr = new ConfigReader();

	public View createView()
	{
		Properties ps = cr.read();
		String daoName = ps.getProperty("DAO");
		String bizName = ps.getProperty("BIZ");
		String viewName = ps.getProperty("VIEW");

		try
		{
			DAO dao = (DAO) Class.forName(daoName).newInstance();
			BIZ biz = (BIZ) Class.forName(bizName).newInstance();
			View view = (View) Class.forName(viewName).newInstance();
			biz.setDAO(dao);
			view.setBIZ(biz);

			return view;
		} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e)
		{
			e.printStackTrace();
			return null;
		}
	}
}
